//file:TransportLib\ProtocolLib.h

#ifndef PROTOCOLLIB_H
#define PROTOCOLLIB_H

#define PROTOCOL_VERSION   0x0001

#define PROTOCOL_RRPF     0x01
#define PROTOCOL_CTPF     0x02
#define PROTOCOL_DTPF     0x03
#define PROTOCOL_CSTPF    0x04
#define PROTOCOL_HBPF     0x05
#define PROTOCOL_CTRPF    0x06

#define PACKET_MAX_LENGTH  0x0400

typedef struct _tag_ProtocolHeader
{
	_tag_ProtocolHeader(void* pSource)
	{
		memcpy((void*)this, pSource, sizeof(_tag_ProtocolHeader));
	}
	bool Check()
	{
		if(this->MagicNum == 0xe2f1 && ProtocolVersion == PROTOCOL_VERSION 
			&& ProtocolFamily >= PROTOCOL_RRPF && ProtocolFamily <= PROTOCOL_CTRPF
			&& (SendMode == 0 || SendMode == 1) && ContentLength <= PACKET_MAX_LENGTH)
		{
			return true;
		}
		return false;
	}
	unsigned short MagicNum;        //2byte
	byte ProtocolVersion;       //1byte
	byte ProtocolFamily;       //1byte
	short Command;              //2byte
	short TargetSessionId;      //2byte
	short SourceSessionId;         //2byte
	short SendMode;                //2byte
	unsigned short ContentLength;  //2byte
}PROTOCOLHEADER,*PPROTOCOLHEADER;


class CKPacket
{
	CKPacket(PPROTOCOLHEADER pProtocolHeader, void* pProtocolBody, int dwBodySize);
	CKPacket(CKPacket& packet);
	~CKPacket();
	CKPacket& operator =(const CKPacket& packet);
	PROTOCOLHEADER m_ProtocolHeader;
	void* m_pProtocolBody;
private:
	int m_dwBodySize;
	
}

#endif